package com.kjsdfgk.hjmdsf.ftvdolist.mvp.model;

import android.app.Application;
import android.util.Base64;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.FragmentScope;

import javax.inject.Inject;

import com.kjsdfgk.hjmdsf.app.api.service.CommonService;
import com.kjsdfgk.hjmdsf.app.entity.XJVideoJson;
import com.kjsdfgk.hjmdsf.ftvdolist.mvp.bean.XJResult;
import com.kjsdfgk.hjmdsf.ftvdolist.mvp.contract.VdoListContract;

import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 04/30/2020 18:02
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@FragmentScope
public class VdoListModel extends BaseModel implements VdoListContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public VdoListModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<XJVideoJson> typeSearch(String uid, int page, String limit, String vod_big_class, String vod_lang,
                                              String vod_source, String vod_year, String vod_actor_class, String vod_class, String vod_area,
                                              String vod_type, String big_vod_class) {
//        String url = "http://app.xjlb4.com/api.php/app_2/typeSearch";
//        String strBase64 = Base64.encodeToString(url.getBytes(), Base64.DEFAULT);
        String   url ="aHR0cDovL2FwcC54amxiNC5jb20vYXBpLnBocC9hcHBfMi90eXBlU2VhcmNo";//
        url =  new String(Base64.decode(url.getBytes(), Base64.DEFAULT));

        Observable<XJVideoJson> result = mRepositoryManager.obtainRetrofitService(CommonService.class).
        typeSearch(url , uid,  page,  limit,  vod_big_class,  vod_lang,
                vod_source,  vod_year,  vod_actor_class,  vod_class,  vod_area,
                vod_type,  big_vod_class);
        return result;
    }


    @Override
    public Observable<String> ccyyHtml(String url) {
//        String url = "http://app.xjlb4.com/api.php/app_2/typeSearch";
//        String strBase64 = Base64.encodeToString(url.getBytes(), Base64.DEFAULT);http://520201.com/

//        url =  new String(Base64.decode(url.getBytes(), Base64.DEFAULT));

        Observable<String> result = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .ccyyHtmlApi( url );

        return result;
    }
}